home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-08 | 13.8 KB | 484 lines | [TEXT/MPS ] |
- /*
-
- File: CappuccinoUndo.cpp
-
-
- Contents: CappuccinoUndo implements undo/redo support for
- the Cappuccino part.
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- Cappuccino Includes --
-
- #ifndef _ACTION_
- #include "Action.h"
- #endif
-
- #ifndef _CAPPUCCINO_
- #include "Cappuccino.h"
- #endif
-
- #ifndef _CAPPUCCINOCONTENT_
- #include "CappuccinoContent.h"
- #endif
-
- #ifndef _CAPPUCCINODEF_
- #include "CappuccinoDef.h"
- #endif
-
- #ifndef _CAPPUCCINOGLOBALS_
- #include "CappuccinoGlobals.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- //==============================================================================
- // CAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- CAction::CAction( Cappuccino* part, ActionCode actionCode )
- {
- fPart = part;
- fActionCode = actionCode;
- }
-
- //------------------------------------------------------------------------------
- // Method: Destructor
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- CAction::~CAction()
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: Do
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- void CAction::Do( Environment* ev )
- {
- this->AddToActionHistory(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: Undo
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- void CAction::Undo( Environment* ev )
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: Redo
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- void CAction::Redo( Environment* ev )
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: GetActionName
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- ODName* CAction::GetActionName( Environment* ev )
- {
- Str255 nameStr;
- ODGetIndString(nameStr, kActionStringResID, fActionCode);
-
- return CreateITextPString(gGlobals->fEditorsScript,
- gGlobals->fEditorsLanguage,
- nameStr);
- }
-
- //------------------------------------------------------------------------------
- // Method: GetUndoRedoName
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- const ODBoolean kUndoName = kODTrue;
- const ODBoolean kRedoName = kODFalse;
-
- ODName* CAction::GetUndoRedoName( Environment* ev,
- ODBoolean isUndo )
- {
- CUsingLibraryResources res;
-
- ODUShort startIndex = (isUndo) ? kUndoPrefixIndex : kRedoPrefixIndex;
-
- // Start withe the prefix.
- Str255 nameStr;
- GetIndString(nameStr, kUndoStringResID, startIndex);
-
- // Concat the action code's name.
- Str255 appendStr;
-
- TempODName actionName = this->GetActionName(ev);
- GetITextPString(actionName, appendStr);
- ConcatPascalStrings(nameStr, appendStr);
-
- // Concat the suffix.
- GetIndString(appendStr, kUndoStringResID, startIndex + 1);
- ConcatPascalStrings(nameStr, appendStr);
-
- return CreateITextPString(gGlobals->fEditorsScript,
- gGlobals->fEditorsLanguage,
- nameStr);
- }
-
- //------------------------------------------------------------------------------
- // Method: AddToActionHistory
- // Origin: CAction
- //------------------------------------------------------------------------------
-
- void CAction::AddToActionHistory( Environment* ev, ODActionType actionType )
- {
- SCappuccionActionState state;
- state.fAction = this;
-
- // Get the undo and redo menu item strings.
- TempODName undoName = this->GetUndoRedoName(ev, kUndoName);
- TempODName redoName = this->GetUndoRedoName(ev, kRedoName);
-
- // Stuff our action data into a ByteArray and add it to the action history.
- ODUndo* undo = ODGetSession(ev, fPart->GetODPart())->GetUndo(ev);
- TempODActionData actionData = CreateByteArray(&state, sizeof state);
-
- undo->AddActionToHistory(ev, fPart->GetODPart(), actionData,
- actionType, undoName, redoName);
- }
-
- //==============================================================================
- // CTextChangeAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CTextChangeAction
- //------------------------------------------------------------------------------
-
- CTextChangeAction::CTextChangeAction( Cappuccino* part,
- ActionCode actionCode,
- CCappuccinoContent* newContent)
- : CAction(part, actionCode)
- {
- fCurrentContent = kODNULL;
- fPreviousContent = kODNULL;
-
- if (newContent)
- newContent->Acquire();
- fCurrentContent = newContent;
- }
-
- //------------------------------------------------------------------------------
- // Method: Destructor
- // Origin: CTextChangeAction
- //------------------------------------------------------------------------------
-
- CTextChangeAction::~CTextChangeAction()
- {
- if (fPreviousContent)
- fPreviousContent->Release();
- if (fCurrentContent)
- fCurrentContent->Release();
- }
-
- //------------------------------------------------------------------------------
- // Method: Do
- // Origin: CTextChangeAction
- //------------------------------------------------------------------------------
-
- void CTextChangeAction::Do( Environment* ev )
- {
- // Get the previous content at the time the action is performed.
- fPreviousContent = fPart->GetContent();
- if (fPreviousContent)
- fPreviousContent->Acquire();
-
- Inherited::Do(ev);
-
- fPart->SetContent(ev, fCurrentContent);
- }
-
- //------------------------------------------------------------------------------
- // Method: Undo
- // Origin: CTextChangeAction
- //------------------------------------------------------------------------------
-
- void CTextChangeAction::Undo( Environment* ev )
- {
- fPart->SetContent(ev, fPreviousContent);
- }
-
- //------------------------------------------------------------------------------
- // Method: Redo
- // Origin: CTextChangeAction
- //------------------------------------------------------------------------------
-
- void CTextChangeAction::Redo( Environment* ev )
- {
- fPart->SetContent(ev, fCurrentContent);
- }
-
- //==============================================================================
- // CClipboardTextChangeAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CClipboardTextChangeAction
- //------------------------------------------------------------------------------
-
- CClipboardTextChangeAction::CClipboardTextChangeAction( Cappuccino* part,
- ActionCode actionCode,
- ODCloneKind cloneKind,
- CCappuccinoContent* content)
- : CTextChangeAction(part, actionCode, content)
- {
- fCloneKind = cloneKind;
- fUpdateID = kODUnknownUpdate;
- }
-
- //------------------------------------------------------------------------------
- // Method: Destructor
- // Origin: CClipboardTextChangeAction
- //------------------------------------------------------------------------------
-
- CClipboardTextChangeAction::~CClipboardTextChangeAction()
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: Do
- // Origin: CClipboardTextChangeAction
- //------------------------------------------------------------------------------
-
- void CClipboardTextChangeAction::Do( Environment* ev )
- {
- ODSession* session = ODGetSession(ev, fPart->GetODPart());
- fUpdateID = session->GetClipboard(ev)->ActionDone(ev, fCloneKind);
- Inherited::Do(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: Undo
- // Origin: CClipboardTextChangeAction
- //------------------------------------------------------------------------------
-
- void CClipboardTextChangeAction::Undo( Environment* ev )
- {
- Inherited::Undo(ev);
-
- // Let the clipboard know.
- WASSERT(fUpdateID != kODUnknownUpdate);
- ODSession* session = ODGetSession(ev, fPart->GetODPart());
- session->GetClipboard(ev)->ActionUndone(ev, fUpdateID, fCloneKind);
- }
-
- //------------------------------------------------------------------------------
- // Method: Redo
- // Origin: CClipboardTextChangeAction
- //------------------------------------------------------------------------------
-
- void CClipboardTextChangeAction::Redo( Environment* ev )
- {
- Inherited::Redo(ev);
-
- // Let the clipboard know.
- WASSERT(fUpdateID != kODUnknownUpdate);
- ODSession* session = ODGetSession(ev, fPart->GetODPart());
- session->GetClipboard(ev)->ActionRedone(ev, fUpdateID, fCloneKind);
- }
-
- //==============================================================================
- // CCutAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CCutAction
- //------------------------------------------------------------------------------
-
- CCutAction::CCutAction( Cappuccino* part )
- : CClipboardTextChangeAction(part, kActionCut, kODCloneCut, kODNULL)
- {
- Environment* ev = somGetGlobalEnvironment(); // ••• make param?
-
- fCurrentContent = new CCappuccinoContent;
- fCurrentContent->InitCappuccinoContent(ev);
- }
-
- //==============================================================================
- // CPasteAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CPasteAction
- //------------------------------------------------------------------------------
-
- CPasteAction::CPasteAction( Cappuccino* part, CCappuccinoContent* content )
- : CClipboardTextChangeAction(part, kActionPaste, kODClonePaste, content)
- {
- }
-
- //==============================================================================
- // CClearAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CClearAction
- //------------------------------------------------------------------------------
-
- CClearAction::CClearAction( Cappuccino* part )
- : CTextChangeAction(part, kActionClear, kODNULL)
- {
- Environment* ev = somGetGlobalEnvironment(); // ••• make param?
-
- fCurrentContent = new CCappuccinoContent;
- fCurrentContent->InitCappuccinoContent(ev);
- }
-
- //==============================================================================
- // CDropAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CDropAction
- //------------------------------------------------------------------------------
-
- CDropAction::CDropAction( Cappuccino* part, CCappuccinoContent* content )
- : CTextChangeAction(part, kActionDrop, content)
- {
- }
-
- //==============================================================================
- // CDragBeginAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CDragBeginAction
- //------------------------------------------------------------------------------
-
- CDragBeginAction::CDragBeginAction( Cappuccino* part )
- : CAction(part, kActionDrag)
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: Do
- // Origin: CDragBeginAction
- //------------------------------------------------------------------------------
-
- void CDragBeginAction::Do( Environment* ev )
- {
- this->AddToActionHistory(ev, kODBeginAction);
- // Don't call Inherited as we're replacing its functionality.
- }
-
- //==============================================================================
- // CDragEndAction
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CDragEndAction
- //------------------------------------------------------------------------------
-
- CDragEndAction::CDragEndAction( Cappuccino* part )
- : CAction(part, kActionDrag)
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: Do
- // Origin: CDragEndAction
- //------------------------------------------------------------------------------
-
- void CDragEndAction::Do( Environment* ev )
- {
- this->AddToActionHistory(ev, kODEndAction);
- // Don't call Inherited as we're replacing its functionality.
- }
-